package com.dhcc.logs.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.dhcc.logs.common.annotation.Log;
import com.dhcc.logs.common.enums.BusinessType;
import com.dhcc.logs.common.response.Result;
import com.dhcc.logs.common.response.ResultCode;
import com.dhcc.logs.entity.User;
import com.dhcc.logs.service.UserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RestController
@Api(tags = "事件接口")
@RequestMapping("/event")
public class PublishEventController {
	private static final Logger log = LoggerFactory.getLogger(PublishEventController.class);

	@Autowired
	UserService userService;
	
    @ApiOperation(value = "注册用户")
    @Log(title = "注册用户", businessType = BusinessType.INSERT)
    @RequestMapping(value = "/registerUser/{name}",method = RequestMethod.GET)
    public Result register(@ApiParam(value = "用户名") @PathVariable(name = "name") String name){
    	log.info("注册用户：" + name);
    	User user = new User();
    	user.setName(name);
    	userService.save(user);
        return new Result(ResultCode.SUCCESS,"注册用户：" + name);
    	
    }
    @ApiOperation(value = "修改用户")
    @Log(title = "修改用户", businessType = BusinessType.UPDATE)
    @RequestMapping(value = "/updateUser/{id}/{name}",method = RequestMethod.PUT)
    public Result update(@ApiParam(value = "用户id") @PathVariable(name = "id") String id,
    		@ApiParam(value = "用户name") @PathVariable(name = "name") String name){
        log.info("修改用户：" + id);
        User user = new User();
    	user.setName(name);
    	user.setId(id);
        userService.update(user);
        return new Result(ResultCode.SUCCESS,"修改用户：" + id);
    }
    @ApiOperation(value = "查询用户")
    @Log(title = "查询用户", businessType = BusinessType.FIND)
    @RequestMapping(value = "/query/{name}",method = RequestMethod.GET)
    public Result query(){
        log.info("查询用户：");
        return new Result(ResultCode.SUCCESS,"查询用户：");
    }
}